package com.itboye.ihomebank.adapter;

import android.content.Context;
import android.database.DataSetObservable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.SystemMessBean;

import java.util.Collection;
import java.util.List;

/**
 * Created by YOLANDA on 2016/7/22.
 */
public class MainAdapter extends BaseecyclerViewAdapter<MainAdapter.ViewHolder> {
    private List<SystemMessBean.Sysitem> mDataList;
    private int mLastPosition = -1;
    public MainAdapter(Context context) {
        super(context);
    }

    public void notifyDataSetChanged(List<SystemMessBean.Sysitem> dataList) {
        this.mDataList = dataList;
        super.notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mDataList == null ? 0 : mDataList.size();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= getInflater().inflate(R.layout.item_menu_main,parent,false);
        return new ViewHolder(view);
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tvTitle.setText(position+":"+mDataList.get(position).getId());
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvTitle;
        public ViewHolder(View itemView) {
            super(itemView);
            tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
        }
    }
    private final DataSetObservable mDataSetObservable = new DataSetObservable();
    /**
     * 通知所附观察员，基础数据已更改，任何反映数据集的视图都应该刷新自己。
     */
    public void notifyListDataSetChanged() {
        mDataSetObservable.notifyChanged();
    }
    public MainAdapter refresh(List<SystemMessBean.Sysitem> list) {
        mDataList.clear();
        mDataList.addAll(list);
        notifyDataSetChanged();
        notifyListDataSetChanged();
        mLastPosition = -1;
        return this;
    }
    public MainAdapter loadmore(List<SystemMessBean.Sysitem> list) {
        mDataList.addAll(list);
        notifyDataSetChanged();
        notifyListDataSetChanged();
        return this;
    }
    //添加一条数据
    public void addData(int position) {
       // mDataList.add(position, "Insert One");
        notifyItemInserted(position);
    }

    //删除一条数据
    public void removeData(int position) {
        mDataList.remove(position);
        notifyItemRemoved(position);
    }

}
